(function(global, doc, $) {
    $(".checkbox").each(function() {
        $(this).click(function() {
            var me = $(this);
            var checked = me[0].checked;
            if(checked){
            	me.addClass("checked");
            }else{
            	me.removeClass("checked");
            }
        });
    });
    $("#aashare").click(function() {
        var selectedItems = $(".checkbox.checked");
        var memberInfo = [];
        selectedItems.each(function() {
            var items = $(this).parent().parent().children();
            var first=items.first();
            var second=first.next();
            var third=second.next();
            var fourth=third.next();
            var fifth=fourth.next();
            var id = second.text();
            var name = third.text();
            var money = fourth.text();
            var num = fifth.children().first().val();
            var info = {
                "id": id,
                "name": name,
                "money": money,
                "num": num
            };
            memberInfo.push(info);
        });
        var cost=$.trim($("#cost").val());
        if(cost&&memberInfo.length<=0){
        	alert("请选择消费人员！");
        	return;
        }
        if(memberInfo.length>0&&!cost){
        	alert("输入消费金额！");
        	return;
        }
        if(!cost||memberInfo.length<=0){
        	alert("请选择消费人员并输入消费金额！");
        	return;
        }
        var datatime=new Date()
        var costInfo = {
            "memberInfo": memberInfo,
            "cost": cost,
            "datetime": datatime.toString()
        };
        var json={
            "verification":{
                "manager":"yanjieyao",
                "word":"iclient"
            },
            "costinfo":costInfo
        }
        console.log(JSON.stringify(json));
        $.ajax({
            url: 'aashare',
            type: 'post',
            dataType: 'html',
            contentType:"application/json",
            data: JSON.stringify(json)
        })
        .done(function(data) {
            doc.write(data);
            console.log("success");
        })
        .fail(function() {
            console.log("error");
        })
        .always(function() {
            console.log("complete");
        });
        ("aashare", json);
    });
}(window, document, jQuery));